{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "8e61b7e1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "200\n",
      "{'request_id': '1680866805,359038d8-178a-4e6d-91af-f956f4600e31', 'time_used': 391, 'faces': [{'face_token': '3aca4e4dd76dc127ffa49dff03351d30', 'face_rectangle': {'top': 841, 'left': 237, 'width': 662, 'height': 662}, 'attributes': {'gender': {'value': 'Male'}}}], 'image_id': 'Far8GVrHAR8cjjXx4vsmzA==', 'face_num': 1}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "人脸识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open(\"D:\\桌面\\dc.jpg\", 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\n",
    "    \"api_key\":\"Y9nxGhuWlm34_TeITNAoeaQswz2BtjTv\",\n",
    "    \"api_secret\":\"gq53hr-I4JXuAXVxhYhwSWAT_DNqkMj4\",\n",
    "    \"image_base64\":img,\n",
    "    \"return_attributes\":\"gender\",\n",
    "}  #参数\n",
    "\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "print (response.status_code)\n",
    "print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "11fb3038",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
